package com.test.threadlocal;

public class ThreadLocalDemo {

    public static ThreadLocal<String> threadLocal = new ThreadLocal<>();

    public static void main(String[] args) {
        ThreadLocalDemo.threadLocal.set("hello world main");
        System.out.println(ThreadLocalDemo.threadLocal.get());

        try {
            Thread thread = new Thread() {
                public void run() {
                    ThreadLocalDemo.threadLocal.set("hello world thread");
                    System.out.println(ThreadLocalDemo.threadLocal.get());
                    ThreadLocalDemo.threadLocal.remove();
                };
            };
            thread.start();
            thread.join();
        } catch (Exception ex) {
            System.out.println(ex);
        } finally {
            ThreadLocalDemo.threadLocal.remove();
        }

        System.out.println(ThreadLocalDemo.threadLocal.get());
    }
}
